package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.api.exception.IFastApiException;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.domain.DictDO;
import com.jinzhi.common.type.ApiEnumError;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.StuSignUpComDO;
import com.jinzhi.jzweb.domain.TrackDrawDO;
import com.jinzhi.jzweb.domain.TrackDrawRegularDO;
import com.jinzhi.jzweb.pojo.TrackDrawRegularVO;
import com.jinzhi.jzweb.service.TrackDrawRegularService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 *
 * <pre>
 * 赛道抽签表（存储抽签信息）
 * </pre>
 * <small> 2023-10-16 16:36:18 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/trackDrawRegularSchool")
public class TrackDrawRegularSchoolController extends BaseController {

	@Autowired
	private TrackDrawRegularService trackDrawRegularService;


	/**
	 *
	 * 抽学校部分
	 *
	 */
	@GetMapping()
	@RequiresPermissions("jzweb:trackDrawRegularSchool:trackDrawRegularSchool")
	String TrackDrawSchool(){
		return "jzweb/trackDrawRegularSchool/trackDrawRegularSchool";
	}



	/**
	 * 对学校进行抽签
	 * @param trackDrawRegularDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/listSchool")
	@RequiresPermissions("jzweb:trackDrawRegularSchool:trackDrawRegularSchool")
	public Result<Set<String>> listSchool(TrackDrawRegularDO trackDrawRegularDTO){


		return trackDrawRegularService.listSchool(trackDrawRegularDTO);
	}


	/**
	 * 对学校进行抽签
	 * @param trackDrawRegularDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/listTrackDrawRegularSchool")
	@RequiresPermissions("jzweb:trackDrawRegularSchool:trackDrawRegularSchool")
	public Result<List<TrackDrawRegularDO>> listTrackDrawRegularSchool(TrackDrawRegularDO trackDrawRegularDTO){

		return trackDrawRegularService.trackRegularListSchool(trackDrawRegularDTO);
	}


	/**
	 * 导出学校抽签结果信息
	 *
	 * @param response
	 */
	@Log("导出学校抽签结果信息")
	@RequestMapping("/downloadImportTemplateSchool")
	@RequiresPermissions("jzweb:trackDrawRegularSchool:import")
	@ResponseBody
	public void downloadImportTemplateSchool(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
		Wrapper<TrackDrawRegularDO> wrapper = new EntityWrapper<>();
		wrapper.orderBy(true,"sort");
		List<TrackDrawRegularDO> trackDrawDOS = trackDrawRegularService.selectList(wrapper);
		if (trackDrawDOS != null && trackDrawDOS.size() > 0) {
			List<TrackDrawRegularVO> drawRegularVOList = new ArrayList<>();
			for (TrackDrawRegularDO trackDrawDO : trackDrawDOS) {
				TrackDrawRegularVO trackDrawRegularVO = new TrackDrawRegularVO();
				BeanUtils.copyProperties(trackDrawDO,trackDrawRegularVO);
				drawRegularVOList.add(trackDrawRegularVO);
			}
			//导出操作
			EasyPoiUtil.exportExcel(drawRegularVOList, "学校抽签信息", "学校抽签信息", TrackDrawRegularVO.class,  "学校抽签信息", response);
		} else {
			throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
		}
	}


}
